package com.rural.bus.driver;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.rural.bus.driver.adapter.OrderAdapter;
import com.rural.bus.driver.model.Order;
import com.rural.bus.driver.utils.VibratorUtil;
import com.rural.bus.driver.view.xlist.XListView;

public class NewOrderActivity extends BaseActivity {
	
	private Button btIgnore;
	private XListView mXlv;
	private List<Order> mOrders=new ArrayList<Order>();
	private OrderAdapter mAdapter;
//	private Speecher speecher;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_neworder);
		
		initView();
		setListeners();
		initData();
		
//        mAdapter.setOrderAction(new IOrderAction() {
//			
//			@Override
//			public void setActionText(Button tv) {
//				
//			}
//			
//			@Override
//			public void action(Context context,Order order) {
//				accept(order);
//			}
//		});
	}
	
	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		action(intent);
	}
	
	private void action(Intent intent){
		Order order=(Order) intent.getSerializableExtra("order");
		if(order!=null){
			mOrders.add(order);
			mAdapter.notifyDataSetChanged();
			VibratorUtil.vibra(this);
		}
	}

	@Override
	public void initData() {
		mAdapter=new OrderAdapter(NewOrderActivity.this,mOrders) ;
		mXlv.setAdapter(mAdapter);
		
		action(getIntent());

//		speecher=Speecher.getSpeecher(this);
		
	}

	@Override
	public void setListeners() {
		
		mImgLeft.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				startActivity(MineActivity.class);
			}
		});

		btIgnore.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
//		speecher.destroy();
	}

	@Override
	protected void initView() {
		btIgnore=(Button) findViewById(R.id.bt_ignore);
		mXlv=(XListView) findViewById(R.id.xlv);
		mXlv.setPullRefreshEnable(false);
		
		mBtMiddle.setText("新订单");
		mBtMiddle.setVisibility(View.VISIBLE);
		mBtMiddle.setTextColor(getResources().getColor(R.color.white));

		mImgLeft.setVisibility(View.VISIBLE);
		mImgLeft.setBackgroundResource(R.drawable.ic_top_bar_bt);
	}

}
